/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package simco.framework.gui.services;

import java.util.ArrayList;
import java.util.List;

import javax.swing.JOptionPane;

import simco.framework.core.ICore;
import simco.framework.gui.utils.LocalizationUtil;
import simco.framework.gui.utils.LoggingUtil;
import simco.framework.models.CompInfo;
import simco.framework.models.MethodInfo;

/**
 * Tato trida slouzi k ziskavani informaci o metodach poskytovanych
 * komponenty prostrednictvim rozhrani.
 * 
 * @author Matej Prokop, mythge@students.zcu.cz
 */
public class MethodInfoProvider implements IMethodInfoProvider
{
	/**
	 * Reference na jadro simulace
	 */
	private ICore core;
	
    /**
     * Vytvori novy objekt poskytujici informace o metodach komponenty
     * 
     * @param core reference na simulacni jadro
     */
	public MethodInfoProvider(ICore core) 
	{
		this.core = core;
	}

	/**
	 * Vrati seznam poskytovanych metod komponentou
	 * s id prijatym jako parametr metody.
	 * 
	 * @param compId id komponenty jejiz seznam metod
	 * 	zjistujeme
	 * @return vraci seznam metod dane komponenty
	 */
	public List<MethodInfo> getMethods(long compId)
    {
    	CompInfo info;
		try 
		{
			info = core.getComponents().get(compId);
		} 
		catch (Exception e) 
		{
			JOptionPane.showMessageDialog(null,
					LocalizationUtil.getGeneralResource().getString("event.coreError") +
					": " + e.getMessage() );
			LoggingUtil.getGuiLogger().error("Pri ziskavani informaci o objektu jadro vratilo chybu!", e);
			return new ArrayList<MethodInfo>();
		}
		
		return info.getMethodInfo();
    }
}
